var instituteInfo = $("#instituteInfo");
var section_id = $("#section_id");

$(document).ready(function() {
});

function doChangeSection(para) {
    $("#section_id").find('option').remove().end();
    var params = encodeURIComponent("instituteId") + "=" + document.getElementById("institute_id").value;
    ajaxPost("?employee/getSectionList", params, function(data) {
        var response = data;
        if (response.status == false) {
            return;
        }
        $('#section_id').append(response);
        $("#section_id").val(para).attr('selected', true);
    });

}
function validateInstitute() {
    var instituteValue = $('#institute_id :selected').val();
    if (instituteValue == 0) {
        //section_id.addClass("errorField");
        instituteInfo.text("Please setect the Institute ");
        instituteInfo.addClass("errorField");
        return false;
    } else {
        instituteInfo.text(" ");
        instituteInfo.removeClass("errorField");
        return true;
    }
}

function print() {


    if (validateInstitute()) {

        var params = encodeURIComponent("month") + "=" + $("#fmonth").val() + "&" + encodeURIComponent("toMonth") + "=" + $("#tmonth").val() + "&" + encodeURIComponent("year") + "=" + $("#fyear").val() + "&" + encodeURIComponent("toYear") + "=" + $("#tyear").val() + "&" + encodeURIComponent("institute") + "=" + $("#institute_id").val() + "&" + encodeURIComponent("section") + "=" + $("#section_id").val();
        //  window.location.href="?print/printDisList&"+params;

        ajaxPost("?print/checkResult", params, function(data) {
            var response = JSON.parse(data);
            if (response.status == false) {
                return;
            }
            if (response.result) {
                printDocument();
                $("#info").html("");
                $("#info").html(response.tableHtml);
            } else {
                $("#info").html("");
                $("#info").html(response.tableHtml);
            }

            //   $("#messagePanel").removeClass();
            //   $("#messagePanel").html("" ) ;


        });
    }


}
function printDocument() {
    var params = encodeURIComponent("month") + "=" + $("#fmonth").val() + "&" + encodeURIComponent("toMonth") + "=" + $("#tmonth").val() + "&" + encodeURIComponent("year") + "=" + $("#fyear").val() + "&" + encodeURIComponent("toYear") + "=" + $("#tyear").val() + "&" + encodeURIComponent("institute") + "=" + $("#institute_id").val() + "&" + encodeURIComponent("section") + "=" + $("#section_id").val();
    var url = "?print/printDisList&" + params;
    //  var win=window.open(url, '_blank');
    // win.focus();
    window.location.href = url;
    // window.open(url, '_blank');
}


function closePage() {
    window.location.href = "?home";
}

function onLoad() {
    enforcePrivileges();
}
onLoad();



